{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Sequential Digits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #enumeration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #枚举"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: sequentialDigits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #顺次数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>我们定义「顺次数」为：每一位上的数字都比前一位上的数字大 <code>1</code> 的整数。</p>\n",
    "\n",
    "<p>请你返回由&nbsp;<code>[low, high]</code>&nbsp;范围内所有顺次数组成的 <strong>有序</strong> 列表（从小到大排序）。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输出：</strong>low = 100, high = 300\n",
    "<strong>输出：</strong>[123,234]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输出：</strong>low = 1000, high = 13000\n",
    "<strong>输出：</strong>[1234,2345,3456,4567,5678,6789,12345]\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>10 &lt;= low &lt;= high &lt;= 10^9</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [sequential-digits](https://leetcode.cn/problems/sequential-digits/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [sequential-digits](https://leetcode.cn/problems/sequential-digits/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['100\\n300', '1000\\n13000']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        nums = []\n",
    "        for i in range(2, 10):  # 长度\n",
    "            for j in range(1, 10 - i + 1):  # 起始\n",
    "                num = \"\"\n",
    "                for k in range(j, j + i):\n",
    "                    num += str(k)\n",
    "                nums.append(int(num))\n",
    "        res = []\n",
    "        for num in nums:\n",
    "            if low<=num<=high:\n",
    "                res.append(num)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        st = \"123456789\"\n",
    "        n = len(st)\n",
    "        res = []\n",
    "        for length in range(2, n + 1):\n",
    "            for i in range(n - length + 1):\n",
    "                res.append(int(st[i:i + length]))\n",
    "        return [num for num in res if low <= num <= high]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "  def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "    v = '123456789'\n",
    "    lv = len(v)\n",
    "    s = len(str(low))\n",
    "    e = len(str(high))\n",
    "    ret = []\n",
    "    for l in range(s, e + 1):\n",
    "      p = 0\n",
    "      for p in range(lv - l + 1):\n",
    "        t = int(v[p:p + l])\n",
    "        # print(f\"try t {t}\")\n",
    "        if t >= low:\n",
    "          if t <= high:\n",
    "            ret.append(t)\n",
    "          else:\n",
    "            break\n",
    "    return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        count1=1\n",
    "        count2=1   \n",
    "        num=['1','2','3','4','5','6','7','8','9']\n",
    "        out=[]\n",
    "        a=low\n",
    "        b=high\n",
    "        while low // 10 !=0 :\n",
    "            low=low//10\n",
    "            count1=count1+1\n",
    "        while high // 10!=0 :\n",
    "            high=high//10\n",
    "            count2=count2+1\n",
    "        if count1==count2:\n",
    "            for i in range(9-count1+1):\n",
    "                if int(''.join(num[i:i+count1]))>=a and int(''.join(num[i:i+count1]))<=b:\n",
    "                    out.append(int(''.join(num[i:i+count1])))\n",
    "        else:\n",
    "            for i in range(count1,count2+1):\n",
    "                for j in range(9-i+1):\n",
    "                    if int(''.join(num[j:j+i]))>=a and int(''.join(num[j:j+i]))<=b:\n",
    "                        out.append(int(''.join(num[j:j+i])))\n",
    "        return out\n",
    "        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "st = \"123456789\"\n",
    "n = len(st)\n",
    "res = []\n",
    "for length in range(2, n + 1):\n",
    "    for i in range(n - length + 1):\n",
    "        res.append(int(st[i:i + length]))\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        return [num for num in res if low <= num <= high]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(1, 10):\n",
    "            num = i\n",
    "            for j in range(i + 1, 10):\n",
    "                num = num * 10 + j\n",
    "                if low <= num <= high:\n",
    "                    ans.append(num)\n",
    "         \n",
    "\n",
    "        print(sorted(ans))\n",
    "        return sorted(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(0, 10):\n",
    "            num = 0 \n",
    "            for j in range(1, 10-i):\n",
    "                num = num * 10 + i + j\n",
    "                if high >= num >= low:\n",
    "                    ans.append(num) \n",
    "        return sorted(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = []\n",
    "        n_l = len(list(str(low)))\n",
    "        n_h = len(list(str(high)))\n",
    "        for i in range(n_l, n_h + 1):\n",
    "            for j in range(1, 11 - i):\n",
    "                num = [str(k) for k in range(j, j + i)]\n",
    "                num = int(''.join(num))\n",
    "                if low <= num <= high:\n",
    "                    ans.append(num)\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(1, 10):\n",
    "            num = i\n",
    "            for j in range(i + 1, 10):\n",
    "                num = num * 10 + j\n",
    "                if low <= num <= high:\n",
    "                    ans.append(num)\n",
    "        return sorted(ans)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        res = []\n",
    "        for i in range(1,10):\n",
    "            num = i\n",
    "            for j in range(i + 1,10):\n",
    "                num = num * 10 + j\n",
    "                if low <= num <= high:\n",
    "                    res.append(num)\n",
    "\n",
    "        return sorted(res)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(1,10):\n",
    "            num = i\n",
    "            for j in range(i+1, 10):\n",
    "                num = num*10 + j\n",
    "                if low <= num <= high:\n",
    "                    ans.append(num)\n",
    "        return sorted(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\r\n",
    "        n = len(str(low))\r\n",
    "        m = len(str(high))\r\n",
    "\r\n",
    "        ret = []\r\n",
    "\r\n",
    "        for i in range(n, m + 1):\r\n",
    "            for j in range(1, 10 - i + 1):\r\n",
    "                x = j\r\n",
    "                for k in range(1, i):\r\n",
    "                    x *= 10\r\n",
    "                    x += k + j\r\n",
    "\r\n",
    "                if low <= x <= high:\r\n",
    "                    ret.append(x)\r\n",
    "                elif x > high:\r\n",
    "                    break\r\n",
    "\r\n",
    "        return ret\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        count1=1\n",
    "        count2=1   \n",
    "        num=['1','2','3','4','5','6','7','8','9']\n",
    "        out=[]\n",
    "        a=low\n",
    "        b=high\n",
    "        while low // 10 !=0 :\n",
    "            low=low//10\n",
    "            count1=count1+1\n",
    "        while high // 10!=0 :\n",
    "            high=high//10\n",
    "            count2=count2+1\n",
    "        if count1==count2:\n",
    "            for i in range(9-count1+1):\n",
    "                if int(''.join(num[i:i+count1]))>=a and int(''.join(num[i:i+count1]))<=b:\n",
    "                    out.append(int(''.join(num[i:i+count1])))\n",
    "        else:\n",
    "            for i in range(count1,count2+1):\n",
    "                for j in range(9-i+1):\n",
    "                    if int(''.join(num[j:j+i]))>=a and int(''.join(num[j:j+i]))<=b:\n",
    "                        out.append(int(''.join(num[j:j+i])))\n",
    "        return out\n",
    "        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(1, 10):\n",
    "            num = i\n",
    "            for j in range(i + 1, 10):\n",
    "                num = num * 10 + j\n",
    "                if low <= num <= high:\n",
    "                    ans.append(num)\n",
    "                if num > high:\n",
    "                    break\n",
    "\n",
    "        print(sorted(ans))\n",
    "        return sorted(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(1, 10):\n",
    "            num = i\n",
    "            for j in range(i + 1, 10):\n",
    "                num = num * 10 + j\n",
    "                if low <= num <= high:\n",
    "                    ans.append(num)\n",
    "        return sorted(ans)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import bisect\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> list[int]:\n",
    "\n",
    "        numbers = '123456789'\n",
    "        ins = []\n",
    "        n = len(numbers)\n",
    "        for i in range(1, n): # i控制长度\n",
    "            for j in range(n - i): # j控制位置\n",
    "                ins.append(int(numbers[j : i + j + 1]))\n",
    "\n",
    "        return ins[bisect.bisect_left(ins, low) : bisect.bisect(ins, high)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        res=[]\n",
    "        s=[1,2,3,4,5,6,7,8,9]\n",
    "        def back(index,cur):\n",
    "            if low<=cur and cur<=high:\n",
    "                res.append(cur)\n",
    "            for i in range(index,9):\n",
    "                if s[i]-cur%10>1 and cur!=0:\n",
    "                    break\n",
    "                tmp=10*cur+s[i]\n",
    "                if tmp<=high:\n",
    "                    back(i+1,tmp)\n",
    "        back(0,0)\n",
    "        return sorted(res)\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        numbers = '123456789'\n",
    "        n = len(numbers)\n",
    "        ans = []\n",
    "        for i in range(1, n+1):\n",
    "            for j in range(n-i+1):\n",
    "                ans.append(numbers[j:j+i])\n",
    "        return [int(x)  for x in ans if low <= int(x) <= high]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        mindigits = len(str(low))\n",
    "        maxdigits = len(str(high))\n",
    "        \n",
    "        def getSeqNum(digits: int, start: int) -> int:\n",
    "            res = 0\n",
    "            for _ in range(digits):\n",
    "                res = res * 10 + start\n",
    "                start += 1\n",
    "            return res\n",
    "        \n",
    "        res = []\n",
    "        most = False\n",
    "        for digits in range(mindigits, maxdigits + 1):\n",
    "            if digits == maxdigits and most:\n",
    "                break\n",
    "            for i in range(1, 11-digits):\n",
    "                num = getSeqNum(digits, i)\n",
    "                if num < low:\n",
    "                    continue\n",
    "                if num > high:\n",
    "                    most = True\n",
    "                    break\n",
    "                res.append(num)\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans=[]\n",
    "        for i in range(1,10):\n",
    "            num=i\n",
    "            for j in range(i+1,10):\n",
    "                num=num*10+j\n",
    "                if low<=num<=high:\n",
    "                    ans.append(num)\n",
    "        return sorted(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = []\n",
    "        n = len(str(low))\n",
    "        \n",
    "        # 生成123，1234，..., 123456789\n",
    "        def generator(n):\n",
    "            beg = 0\n",
    "            for i in range(n):\n",
    "                beg = 10 * beg + (i+1)\n",
    "            return beg\n",
    "        sumNum = int('1'*n)\n",
    "        beg = generator(n)\n",
    "        while beg <= high:\n",
    "            if beg >= low:\n",
    "                ans.append(beg)\n",
    "            beg += sumNum\n",
    "            if beg % 10 == 0:\n",
    "                n += 1\n",
    "                beg = generator(n)\n",
    "                sumNum = sumNum * 10 + 1\n",
    "        return ans\n",
    "             "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(1, 10):\n",
    "            x = i\n",
    "            for j in range(i + 1, 10):\n",
    "                x = x*10 + j\n",
    "                if low <= x <= high:\n",
    "                    ans.append(x)\n",
    "        return sorted(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        返回数组 = []\n",
    "        for i in range(1, 9):\n",
    "            x = i\n",
    "            for j in range(i+1, 10):\n",
    "                x = x*10+j\n",
    "                if low <= x <= high:\n",
    "                    返回数组.append(x)\n",
    "        return sorted(返回数组)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        l = [12,23,34,45,56,67,78,89,123,234,345,456,567,678,789,1234,2345,3456,4567,5678,6789,12345,23456,34567,45678,56789,123456,234567,345678,456789,1234567,2345678,3456789,12345678,23456789,123456789]\n",
    "        ans = []\n",
    "        for x in l:\n",
    "            if low <= x <= high: ans.append(x)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = []\n",
    "        candidates = [12,23,34,45,56,67,78,89,123,234,345,456,567,678,789,1234,2345,3456,4567,5678,6789,12345,23456,34567,45678,56789,123456,234567,345678,456789,1234567,2345678,3456789,12345678,23456789,123456789]\n",
    "        for x in candidates:\n",
    "            if low <= x <= high:\n",
    "                ans.append(x)\n",
    "        return ans\n",
    "        '''\n",
    "        lows,highs,ans = [],[],[]\n",
    "        original_low,original_high = low,high\n",
    "        while original_low:\n",
    "            lows.append(original_low%10)\n",
    "            original_low //= 10\n",
    "        lows.reverse()\n",
    "        while original_high:\n",
    "            highs.append(original_high%10)\n",
    "            original_high //= 10\n",
    "        highs.reverse()\n",
    "        m,n = len(lows), len(highs)\n",
    "        #print(lows,highs)\n",
    "        start = lows[0]\n",
    "        end = start+m-1\n",
    "        if end > 9:\n",
    "            start = 1\n",
    "            m += 1\n",
    "        end = start+m-1\n",
    "        while end <= 9:\n",
    "            candiate = []\n",
    "            for i in range(m):\n",
    "                candiate.append(start+i)\n",
    "            #print(candiate)\n",
    "            number = 0\n",
    "            for num in candiate:\n",
    "                number = number*10 + num\n",
    "            #print(number,high)\n",
    "            if number > high:\n",
    "                return ans\n",
    "            else:\n",
    "                if number >= low:\n",
    "                    ans.append(number)\n",
    "            start += 1\n",
    "            end = start+m-1\n",
    "            if end > 9:\n",
    "                start = 1\n",
    "                m += 1\n",
    "            end = start+m-1\n",
    "            #print(start,end,k,ans)\n",
    "        return ans\n",
    "        '''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        x = '123456789'\n",
    "        arr = [12, 23, 34, 45, 56, 67, 78, 89, 123, 234, 345, 456, 567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789, 12345, 23456, 34567, 45678, 56789, 123456, 234567, 345678, 456789, 1234567, 2345678, 3456789, 12345678, 23456789, 123456789]\n",
    "        result = []\n",
    "        for i in arr:\n",
    "            if i>=low and i <= high:\n",
    "                result.append(i)\n",
    "                if i>high:\n",
    "                    break\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(1, 10):\n",
    "            for j in range(1, 11 - i):\n",
    "                cur = 0\n",
    "                for k in range(j, j + i):\n",
    "                    cur = cur * 10 + k\n",
    "                if cur > high:\n",
    "                    return ans\n",
    "                if cur >= low:\n",
    "                    ans.append(cur)\n",
    "        return ans\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "\n",
    "        numbers = '123456789'\n",
    "        ins = []\n",
    "        n = len(numbers)\n",
    "        for i in range(1, n): # i控制长度\n",
    "            for j in range(n - i): # j控制位置\n",
    "                ins.append(int(numbers[j : i + j + 1]))\n",
    "        print(ins)\n",
    "\n",
    "        return [x for x in ins if x >= low and x <= high]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        res = []\n",
    "        answers = [12, 23, 34, 45, 56, 67, 78, 89, 123, 234, 345, 456, 567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789, 12345, 23456, 34567, 45678, 56789, 123456, 234567, 345678, 456789, 1234567, 2345678, 3456789, 12345678, 23456789, 123456789]\n",
    "        for i in answers:\n",
    "            if i >= low and i <= high:\n",
    "                res.append(i)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import deque\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        result = list()\n",
    "        dq = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])\n",
    "        depth = 0\n",
    "        while dq:\n",
    "            depth += 1\n",
    "            for _ in range(len(dq)):\n",
    "                num = dq.popleft()\n",
    "                if low <= num <= high:\n",
    "                    result.append(num)\n",
    "                if num > high:\n",
    "                    continue\n",
    "                last_num = int(str(num)[-1])\n",
    "                next_num = last_num + 1\n",
    "                if next_num <= 9:\n",
    "                    dq.append(num * 10 + next_num)\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        count1=1\n",
    "        count2=1   \n",
    "        num=['1','2','3','4','5','6','7','8','9']\n",
    "        out=[]\n",
    "        a=low\n",
    "        b=high\n",
    "        while low // 10 !=0 :\n",
    "            low=low//10\n",
    "            count1=count1+1\n",
    "        while high // 10!=0 :\n",
    "            high=high//10\n",
    "            count2=count2+1\n",
    "        if count1==count2:\n",
    "            for i in range(9-count1+1):\n",
    "                if int(''.join(num[i:i+count1]))>=a and int(''.join(num[i:i+count1]))<=b:\n",
    "                    out.append(int(''.join(num[i:i+count1])))\n",
    "        else:\n",
    "            for i in range(count1,count2+1):\n",
    "                for j in range(9-i+1):\n",
    "                    if int(''.join(num[j:j+i]))>=a and int(''.join(num[j:j+i]))<=b:\n",
    "                        out.append(int(''.join(num[j:j+i])))\n",
    "        return out\n",
    "        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        obj_list = []\n",
    "        for i in range(len(str(low)), len(str(high)) + 1):\n",
    "            obj = '1'\n",
    "            add_value = int('1' * i)\n",
    "            for j in range(1, i):\n",
    "                obj += str(int(obj[-1]) + 1)\n",
    "            print(obj)\n",
    "            while True:\n",
    "                if low <= int(obj) <= high:\n",
    "                    obj_list.append(int(obj))\n",
    "                if str(obj)[-1] == '9':\n",
    "                    break\n",
    "                obj = str(int(obj) + add_value)\n",
    "\n",
    "        print(obj_list)\n",
    "        return obj_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        lows = []\n",
    "        highs = []\n",
    "        ans = []\n",
    "        original_low,original_high = low,high\n",
    "        while original_low:\n",
    "            lows.append(original_low%10)\n",
    "            original_low //= 10\n",
    "        lows.reverse()\n",
    "        while original_high:\n",
    "            highs.append(original_high%10)\n",
    "            original_high //= 10\n",
    "        highs.reverse()\n",
    "        m,n = len(lows), len(highs)\n",
    "        print(lows,highs)\n",
    "        start = lows[0]\n",
    "        k = 0\n",
    "        end = start+m-1\n",
    "        if end > 9:\n",
    "            start = 1\n",
    "            k += 1\n",
    "        end = start+m-1+k\n",
    "        while end <= 9:\n",
    "            candiate = []\n",
    "            for i in range(m+k):\n",
    "                candiate.append(start+i)\n",
    "            print(candiate)\n",
    "            number = 0\n",
    "            for num in candiate:\n",
    "                number = number*10 + num\n",
    "            print(number,high)\n",
    "            if number > high:\n",
    "                return ans\n",
    "            else:\n",
    "                if number >= low:\n",
    "                    ans.append(number)\n",
    "            start += 1\n",
    "            end = start+m-1+k\n",
    "            if end > 9:\n",
    "                start = 1\n",
    "                k += 1\n",
    "            end = start+m-1+k\n",
    "            print(start,end,k,ans)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\r\n",
    "        n, ans = len(str(low)), []\r\n",
    "        while n < 10:\r\n",
    "            for i in range(1, 11 - n):\r\n",
    "                x = int(\"0123456789\"[i : i + n])\r\n",
    "                if x > high: return ans\r\n",
    "                if x >= low: ans.append(x)\r\n",
    "            n += 1\r\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# 枚举\n",
    "ALL = (12, 23, 34, 45, 56, 67, 78, 89, 123, 234, 345, 456, 567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789, 12345, 23456, 34567, 45678, 56789, 123456, 234567, 345678, 456789, 1234567, 2345678, 3456789, 12345678, 23456789, 123456789)\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        return ALL[bisect_left(ALL, low) : bisect_right(ALL, high)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        nums = []\n",
    "        for i in range(1, 10):\n",
    "            num = i\n",
    "            for j in range(i+1, 10):\n",
    "                num = num * 10 + j\n",
    "                nums.append(num)\n",
    "        nums.sort()\n",
    "        res = []\n",
    "        for num in nums:\n",
    "            if num >= low and num <= high:\n",
    "                res.append(num)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "  def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "    v = '123456789'\n",
    "    lv = len(v)\n",
    "    s = len(str(low))\n",
    "    e = len(str(high))\n",
    "    ret = []\n",
    "    for l in range(s, e + 1):\n",
    "      p = 0\n",
    "      for p in range(lv - l + 1):\n",
    "        t = int(v[p:p + l])\n",
    "        # print(f\"try t {t}\")\n",
    "        if t >= low:\n",
    "          if t <= high:\n",
    "            ret.append(t)\n",
    "          else:\n",
    "            break\n",
    "    return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = list()\n",
    "        for i in range(1, 10):\n",
    "            num = i\n",
    "            for j in range(i + 1, 10):\n",
    "                num = num * 10 + j\n",
    "                if low <= num <= high:\n",
    "                    ans.append(num)\n",
    "                if num > high:\n",
    "                    break\n",
    "\n",
    "        print(sorted(ans))\n",
    "        return sorted(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# 枚举\n",
    "ALL = (12, 23, 34, 45, 56, 67, 78, 89, 123, 234, 345, 456, 567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789, 12345, 23456, 34567, 45678, 56789, 123456, 234567, 345678, 456789, 1234567, 2345678, 3456789, 12345678, 23456789, 123456789)\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        return [i for i in ALL if low <= i <= high]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = []\n",
    "        for i in range(1,10):\n",
    "            num = i\n",
    "            for j in range(i+1, 10):\n",
    "                num = num*10+j\n",
    "                if low <= num <= high:\n",
    "                    ans.append(num)\n",
    "        return sorted(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        x = '123456789'\n",
    "        arr = [12, 23, 34, 45, 56, 67, 78, 89, 123, 234, 345, 456, 567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789, 12345, 23456, 34567, 45678, 56789, 123456, 234567, 345678, 456789, 1234567, 2345678, 3456789, 12345678, 23456789, 123456789]\n",
    "        result = []\n",
    "        for i in arr:\n",
    "            if i>=low and i <= high:\n",
    "                result.append(i)\n",
    "                if i>high:\n",
    "                    break\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# 枚举\n",
    "ALL = (12, 23, 34, 45, 56, 67, 78, 89, 123, 234, 345, 456, 567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789, 12345, 23456, 34567, 45678, 56789, 123456, 234567, 345678, 456789, 1234567, 2345678, 3456789, 12345678, 23456789, 123456789)\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        return [i for i in ALL if low <= i <= high]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        result = []\n",
    "        for i in range(1,10):\n",
    "            num = i\n",
    "            for j in range(i+1,10):\n",
    "                num = num * 10 + j\n",
    "                if num >= low and num <= high:\n",
    "                    result.append(num)\n",
    "        result.sort()\n",
    "        return result\n",
    "        '''\n",
    "        def check(num):\n",
    "            strnum = str(num)\n",
    "            for i in range(1,len(strnum)):\n",
    "                if int(strnum[i]) != int(strnum[i-1])+1:\n",
    "                    return False\n",
    "            return True\n",
    "        result = []\n",
    "        for i in range(low,high+1):\n",
    "            if check(i):\n",
    "                result.append(i)\n",
    "        return result\n",
    "        '''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        x = '123456789'\n",
    "        arr = [12, 23, 34, 45, 56, 67, 78, 89, 123, 234, 345, 456, 567, 678, 789, 1234, 2345, 3456, 4567, 5678, 6789, 12345, 23456, 34567, 45678, 56789, 123456, 234567, 345678, 456789, 1234567, 2345678, 3456789, 12345678, 23456789, 123456789]\n",
    "        result = []\n",
    "        for i in arr:\n",
    "            if i>=low and i <= high:\n",
    "                result.append(i)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        result = []\n",
    "        for i in range(1,10):\n",
    "            num = i\n",
    "            for j in range(i+1,10):\n",
    "                num = num * 10 + j\n",
    "                if num >= low and num <= high:\n",
    "                    result.append(num)\n",
    "        result.sort()\n",
    "        return result\n",
    "        '''\n",
    "        def check(num):\n",
    "            strnum = str(num)\n",
    "            for i in range(1,len(strnum)):\n",
    "                if int(strnum[i]) != int(strnum[i-1])+1:\n",
    "                    return False\n",
    "            return True\n",
    "        result = []\n",
    "        for i in range(low,high+1):\n",
    "            if check(i):\n",
    "                result.append(i)\n",
    "        return result\n",
    "        '''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        ans = list()\n",
    "        n = len(str(low))\n",
    "\n",
    "        while n < 10:\n",
    "            for i in range(1, 11 - n):\n",
    "                x = int('0123456789'[i:i + n])\n",
    "                if low <= x <= high:\n",
    "                    ans.append(x)\n",
    "            n += 1\n",
    "        print(ans)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> list[int]:\n",
    "        ans=[]\n",
    "        for i in range(1,10):\n",
    "            s=str(i)\n",
    "            for j in range(9):\n",
    "                if int(s[j])+1>=10:\n",
    "                    break\n",
    "                s+=str(int(s[j])+1)\n",
    "                if int(s) in range(low,high+1):\n",
    "                    ans.append(int(s))\n",
    "        return sorted(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        返回数组 = []\n",
    "        x = 0\n",
    "        进位 = 10\n",
    "        for i in range(1, 10):\n",
    "            进位 *= 10\n",
    "            x = x * 10 + i\n",
    "            if x*10 > high:\n",
    "                return 返回数组\n",
    "            y = x\n",
    "            for j in range(i+1, 10):\n",
    "                y = (y*10+j)%进位\n",
    "                print(x, y, low, high)\n",
    "                if low <= y <= high:\n",
    "                    返回数组.append(y)\n",
    "        return 返回数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        count1=1\n",
    "        count2=1   \n",
    "        num=['1','2','3','4','5','6','7','8','9']\n",
    "        out=[]\n",
    "        a=low\n",
    "        b=high\n",
    "        while low // 10 !=0 :\n",
    "            low=low//10\n",
    "            count1=count1+1\n",
    "        while high // 10!=0 :\n",
    "            high=high//10\n",
    "            count2=count2+1\n",
    "        if count1==count2:\n",
    "            for i in range(9-count1+1):\n",
    "                if int(''.join(num[i:i+count1]))>=a and int(''.join(num[i:i+count1]))<=b:\n",
    "                    out.append(int(''.join(num[i:i+count1])))\n",
    "        else:\n",
    "            for i in range(count1,count2+1):\n",
    "                for j in range(9-i+1):\n",
    "                    if int(''.join(num[j:j+i]))>=a and int(''.join(num[j:j+i]))<=b:\n",
    "                        out.append(int(''.join(num[j:j+i])))\n",
    "        return out\n",
    "        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        lst1=[]\n",
    "        lst=[12,23,34,45,56,67,78,89,123,234,345,456,567,678,789,1234,2345,3456,4567,5678,6789,12345,23456,34567,45678,56789,123456,234567,345678,456789,1234567,2345678,3456789,12345678,23456789,123456789]\n",
    "        for num in lst:\n",
    "            if  low<=num<=high:\n",
    "                lst1.append(num)\n",
    "        return lst1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        s = '123456789'\n",
    "        ans = []\n",
    "        for i in range(len(str(low)), len(str(high)) + 1):\n",
    "            for j in range(0, 10 - i):\n",
    "                if low <= int(s[j : j + i]) <= high:\n",
    "                    ans.append(int(s[j : j + i]))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        res = []\n",
    "        for num in range(1, 10):\n",
    "            number = num\n",
    "            next_num = num\n",
    "\n",
    "            while number <= high:\n",
    "                if low <= number:\n",
    "                    res.append(number)\n",
    "                next_num += 1\n",
    "                if next_num > 9:\n",
    "                    break\n",
    "                number = number * 10 + next_num\n",
    "        res.sort()\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        res=[]\n",
    "        for i in range(1,10):\n",
    "            num = i\n",
    "            for j in range(i+1,10):\n",
    "                num=num*10+j\n",
    "                if low<=num<=high:\n",
    "                    res.append(num)\n",
    "        return sorted(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import bisect\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> list[int]:\n",
    "\n",
    "        numbers = '123456789'\n",
    "        ins = [\n",
    "            12, \n",
    "            23, \n",
    "            34, \n",
    "            45, \n",
    "            56, \n",
    "            67, \n",
    "            78, \n",
    "            89, \n",
    "            123, \n",
    "            234, \n",
    "            345, \n",
    "            456, \n",
    "            567, \n",
    "            678, \n",
    "            789, \n",
    "            1234, \n",
    "            2345, \n",
    "            3456, \n",
    "            4567, \n",
    "            5678, \n",
    "            6789, \n",
    "            12345, \n",
    "            23456, \n",
    "            34567, \n",
    "            45678, \n",
    "            56789, \n",
    "            123456, \n",
    "            234567, \n",
    "            345678, \n",
    "            456789, \n",
    "            1234567, \n",
    "            2345678, \n",
    "            3456789, \n",
    "            12345678, \n",
    "            23456789, \n",
    "            123456789\n",
    "            ]\n",
    "\n",
    "        return ins[bisect.bisect_left(ins, low) : bisect.bisect(ins, high)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\n",
    "        s = \"123456789\"\n",
    "        l = []\n",
    "        ans = []\n",
    "        for i in range(2, 10):\n",
    "            j = 0\n",
    "            while j + i < 10:\n",
    "                l.append(int(s[j: j + i]))\n",
    "                j += 1\n",
    "        for i in l:\n",
    "            if i >= low and i <= high:\n",
    "                ans.append(i)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def sequentialDigits(self, low: int, high: int) -> List[int]:\r\n",
    "        ans = list()\r\n",
    "        for i in range(1, 10):\r\n",
    "            j = i\r\n",
    "            while j <= high and i + 1 < 10:\r\n",
    "                j = j * 10 + i + 1\r\n",
    "                i += 1\r\n",
    "                if low <= j <= high:\r\n",
    "                    ans.append(j)\r\n",
    "        return sorted(ans)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
